package com.imut.lagain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * 閫氱煡瀹炰綋绫?
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("notification")
public class Notification implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 涓婚敭ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 鎺ユ敹鐢ㄦ埛ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 鍙戦€佺敤鎴稩D锛堝彲閫夛級
     */
    @TableField("from_user_id")
    private Long fromUserId;

    /**
     * 妯℃澘浠ｇ爜
     */
    @TableField("template_code")
    private String templateCode;

    /**
     * 妯℃澘ID
     */
    @TableField("template_id")
    private Long templateId;

    /**
     * 閫氱煡绫诲瀷
     */
    @TableField("type")
    private NotificationType type;

    /**
     * 閫氱煡鏍囬
     */
    @TableField("title")
    private String title;

    /**
     * 閫氱煡鍐呭
     */
    @TableField("content")
    private String content;

    /**
     * 璺宠浆URL
     */
    @TableField("jump_url")
    private String jumpUrl;

    /**
     * 闄勫姞鏁版嵁
     */
    @TableField("extra_data")
    private Map<String, Object> extraData;

    /**
     * 閫氱煡鐘舵€?
     */
    @TableField("status")
    private NotificationStatus status;

    /**
     * 浼樺厛绾?
     */
    @TableField("priority")
    private Integer priority;

    /**
     * 杩囨湡鏃堕棿
     */
    @TableField("expire_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime expireAt;

    /**
     * 闃呰鏃堕棿
     */
    @TableField("read_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime readAt;

    /**
     * 鍙戦€佹椂闂?
     */
    @TableField("sent_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sentAt;

    /**
     * 閲嶈瘯娆℃暟
     */
    @TableField("retry_count")
    private Integer retryCount;

    /**
     * 鏈€鍚庨噸璇曟椂闂?
     */
    @TableField("last_retry_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastRetryAt;

    /**
     * 閿欒淇℃伅
     */
    @TableField("error_message")
    private String errorMessage;

    /**
     * 鍒涘缓鏃堕棿
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    /**
     * 鏇存柊鏃堕棿
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedAt;

    /**
     * 鏄惁宸茶
     */
    @TableField("is_read")
    private Boolean isRead;

    /**
     * 鏄惁宸插彂閫佸井淇￠€氱煡
     */
    @TableField("wechat_sent")
    private Boolean wechatSent;

    /**
     * 寰俊鍙戦€佹椂闂?
     */
    @TableField("wechat_sent_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime wechatSentAt;

    /**
     * 璁″垝鍙戦€佹椂闂?
     */
    @TableField("schedule_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime scheduleTime;

    /**
     * 鏄惁鍒犻櫎
     */
    @TableField("is_deleted")
    @TableLogic
    private Boolean isDeleted;

    /**
     * 閫氱煡绫诲瀷鏋氫妇
     */
    public enum NotificationType {
        SYSTEM,     // 绯荤粺閫氱煡
        USER,       // 鐢ㄦ埛閫氱煡
        REMINDER,   // 鎻愰啋閫氱煡
        ACTIVITY,   // 娲诲姩閫氱煡
        SECURITY    // 瀹夊叏閫氱煡
    }

    /**
     * 閫氱煡鐘舵€佹灇涓?
     */
    public enum NotificationStatus {
        PENDING,    // 寰呭彂閫?
        SENT,       // 宸插彂閫?
        READ,       // 宸茶
        EXPIRED,    // 宸茶繃鏈?
        FAILED      // 鍙戦€佸け璐?
    }

    // 鎵嬪姩娣诲姞setter鏂规硶浠ョ‘淇濈紪璇戦€氳繃
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public void setStatus(NotificationStatus status) {
        this.status = status;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public void setType(NotificationType type) {
        this.type = type;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setExtraData(Map<String, Object> extraData) {
        this.extraData = extraData;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public void setIsDeleted(Boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    public void setTemplateId(Long templateId) {
        this.templateId = templateId;
    }

    public void setJumpUrl(String jumpUrl) {
        this.jumpUrl = jumpUrl;
    }

    public void setExpireAt(LocalDateTime expireAt) {
        this.expireAt = expireAt;
    }

    public void setFromUserId(Long fromUserId) {
        this.fromUserId = fromUserId;
    }

    public void setIsRead(Boolean isRead) {
        this.isRead = isRead;
    }

    public Boolean getIsRead() {
        return isRead;
    }

    public void setReadAt(LocalDateTime readAt) {
        this.readAt = readAt;
    }

    public Long getId() {
        return id;
    }

    public Long getUserId() {
        return userId;
    }

    public NotificationStatus getStatus() {
        return status;
    }

    public NotificationType getType() {
        return type;
    }

    public String getTitle() {
        return title;
    }

    public String getContent() {
        return content;
    }

    public Long getTemplateId() {
        return templateId;
    }

    public Map<String, Object> getData() {
        return extraData;
    }

    public Map<String, Object> getExtraData() {
        return extraData;
    }

    public LocalDateTime getReadAt() {
        return readAt;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public String getJumpUrl() {
        return jumpUrl;
    }

    public Boolean getWechatSent() {
        return wechatSent;
    }

    public void setWechatSent(Boolean wechatSent) {
        this.wechatSent = wechatSent;
    }

    public LocalDateTime getWechatSentAt() {
        return wechatSentAt;
    }

    public void setWechatSentAt(LocalDateTime wechatSentAt) {
        this.wechatSentAt = wechatSentAt;
    }

    public String getTemplateCode() {
        return templateCode;
    }

    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }

    public LocalDateTime getScheduleTime() {
        return scheduleTime;
    }

    public void setScheduleTime(LocalDateTime scheduleTime) {
        this.scheduleTime = scheduleTime;
    }
}